﻿/*
	Copyright 2008 CATsoft Development GmbH

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/
/*
	Options
*/
/***********************************************************************
  Initialize
***********************************************************************/
function options_onopen(){

	iconsize.value = options.getValue( "iconSize" );
	opacity.value = options.getValue( "opacity" );
 

	entry = "<listbox height=\"122\" name=\"lblists\" width=\"342\" x=\"4\" y=\"44\" background=\"#FFFFFF\" itemWidth=\"346\" itemHeight=\"20\"" 
	entry = entry + " itemOverColor=\"#30FFFFFF\" autoscroll=\"true\" itemSelectedColor=\"#30FFFFFF\"/>"
	divmain.AppendElement( entry );

	showListbox();
}

/***********************************************************************
  Show Directories
***********************************************************************/
function showListbox(){
var dirs = restoreDirs();
	
		
		lblists.RemoveAllElements();

		for(var i = 0;i< dirs.length;i++)
		{
				var dir = dirs[i];
				entry = "<item height=\"20\" width=\"342\" name=\"" + i+ "\">" 
				entry = entry + "<label x=\"0\" y=\"1\" height=\"18\" width=\"310\" name=\"li" + i + "\" color=\"#000000\" font=\"tahoma\" size=\"8\">" + dir+ "</label>";
				entry = entry +  "<checkbox height=\"20\" name=\"cbx" + i + "\" width=\"16\" x=\"310\" y=\"0\" downImage=\"stock_images\\checkbox_down.png\" value=\"0\" ";
        entry = entry + "image=\"stock_images\\checkbox_up.png\" overImage=\"stock_images\\checkbox_over.png\" caption=\"\" checkedDownImage=\"stock_images\\checkbox_checked_down.png\" ";
        entry = entry + "checkedImage=\"stock_images\\checkbox_checked_up.png\" checkedOverImage=\"stock_images\\checkbox_checked_over.png\" onclick=\"removeDir('" + dir.replace(/\\/g,"\\\\") + "')\"/>";
				entry = entry + "</item>";
				lblists.AppendElement(entry);
			}
}

/***********************************************************************
  Remove selected directory
***********************************************************************/
function removeDir( dir ){
	var dirs = restoreDirs();
	var newDirs = new Array();
	
	for( var i = 0; i < dirs.length; i++ )
	{
		if( dirs[i] != dir )
			newDirs.push( dirs[i] );			
	}
	saveDirs(newDirs );
	showListbox();
}

/***********************************************************************
  Save
***********************************************************************/
function options_onok(){
	options.putValue( "iconSize", iconsize.value );
	options.putValue( "opacity", opacity.value );

}